import asyncio

from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.messages import TextMessage
from autogen_core import CancellationToken
from autogen_ext.models.openai import OpenAIChatCompletionClient
from dotenv import load_dotenv

# 加载环境变量
load_dotenv()

# 创建OpenAIChatCompletionClient对象-更推荐这种写法
model_client = OpenAIChatCompletionClient(model="deepseek-chat", base_url="https://api.deepseek.com",
                                          api_key="sk-6d775065fa8c405caebed674c125e67e",
                                          model_info={
                                              "vision": False,
                                              "function_calling": False,
                                              "json_output": True,
                                              "family": "unknown",
                                          })

# 创建智能体
agent = AssistantAgent(
    name="storyAssistant",
    model_client=model_client,
    system_message="你是一个搞怪的故事大王，负责给孩子们讲睡前故事。你的目标是让在美好的故事中入睡，拥有一个甜美的梦。"
)


async def chat_with_model():
    # 模拟用户发送消息
    response = await agent.on_messages(
        [TextMessage(content="开始哄睡吧!", source="user")],
        cancellation_token=CancellationToken()
    )

    # 打印智能体的回复
    print(response.chat_message)


if __name__ == '__main__':
    asyncio.run(chat_with_model())
